package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Mapper


public interface OrderMapper {
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select *from orders where status=#{status} AND order_time<#{beforeTime15}")
    List<Orders> getBystatusAndOrderTime(@Param("status") Integer status, @Param("beforeTime15") LocalDateTime beforeTime15);


    @Select("SELECT * FROM orders WHERE id=#{id}")
    Orders getById(Long id);

    @Select("SELECT * FROM orders WHERE user_id=#{userId}")
    List<Orders> getByUserId(Long userId);

    Page<Orders> pageQuery(OrdersPageQueryDTO oq);


    @Update("UPDATE orders set status = 6 where id=#{id}")
    void cancelorder(Long id);



    @Update("update orders set status = #{arg0},pay_status = #{arg1} ,checkout_time = #{arg2} " +
            "where number = #{arg3}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, String orderNumber);


    @Select("SELECT COUNT(id) FROM orders where status=#{status}")
    Integer getByStatus(Integer status);

}
